<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ClassControl.ascx.cs" Inherits="Awaken.CodeGen.Controls.ClassControl" %>
using System;
using System.Collections;
using System.Web.UI.WebControls;

using Awaken.Framework;
using Nullables;

namespace <%= this.Namespace %>
{
    public partial class <%= this.ClassName %> : IEntity
    {
        protected static <%= this.ClassName %>Broker broker;
        public static <%= this.ClassName %>Broker Broker
        {
            get
            {
                if (broker == null)
                {
                    broker = new <%= this.ClassName %>Broker();
                }
                return broker;
            }
        }

        #region IEntity Members

        public string EntityID
        {
            get { return string.Empty; }
        }
        
        public string EntityName
        {
            get { return string.Empty; }
        }

        public void Save()
        {
            Broker.Save(this);
        }
        
        public void Delete()
        {
            Broker.Delete(this);
        }
        
        #endregion
    
        #region Constructor
        
        public <%= this.ClassName %>()
        {
            // Default, no arg constructor.
        }
        
        #endregion
            
        #region Public Properties / Protected Fields
                        
        <asp:Repeater ID="propertyRepeater" runat="server">
        <ItemTemplate>
        protected <%# Eval("CSharpTypeName")%> _<%# Eval("PropertyName")%>;
        public <%# Eval("CSharpTypeName")%> <%# Eval("PropertyName")%>
        {
            get{ return _<%# Eval("PropertyName")%>; }
            set{ _<%# Eval("PropertyName")%>=value; }
        }
        </ItemTemplate>
        </asp:Repeater>
        
        <asp:Repeater ID="oneToManyRepeater" runat="server">
        <ItemTemplate>
        // One-To-Many: <%# Eval("OtherTableName")%>.<%# Eval("OtherTableColumnName")%>  
        protected IList _<%# Eval("OtherTableCollectionName")%>;
        public IList <%# Eval("OtherTableCollectionName")%>
        {
            get{ return _<%# Eval("OtherTableCollectionName")%>; }
            set{ _<%# Eval("OtherTableCollectionName")%>=value; }
        }
        </ItemTemplate>
        </asp:Repeater>
        
        <asp:Repeater ID="manyToOneRepeater" runat="server">
        <ItemTemplate>
        // Many-To-One: <%# Eval("OtherTableName")%>.<%# Eval("OtherTableColumnName")%>
        protected <%# Eval("OtherTableClassName")%> _<%# Eval("OtherTableClassName")%>;
        public <%# Eval("OtherTableClassName")%> <%# Eval("OtherTableClassName")%>
        {
            get{ return _<%# Eval("OtherTableClassName")%>; }
            set{ _<%# Eval("OtherTableClassName")%>=value; }
        }
        </ItemTemplate>
        </asp:Repeater>        
        
        <asp:Repeater ID="manyToManyRepeater" runat="server">
        <ItemTemplate>
        // Many-To-Many: <%# Eval("ManyToManyTableName")%>
        protected IList _<%# Eval("OtherTableCollectionName")%>;
        public IList <%# Eval("OtherTableCollectionName")%>
        {
            get{ return _<%# Eval("OtherTableCollectionName")%>; }
            set{ _<%# Eval("OtherTableCollectionName")%>=value; }
        }
        </ItemTemplate>
        </asp:Repeater>
        
        #endregion
    }
    
    #region <%= this.ClassName %>Broker

    public partial class <%= this.ClassName %>Broker : IBroker
    {
        #region IBroker Members

        public Type EntityType
        {
            get { return typeof(<%= this.ClassName %>); }
        }
        
        public <%= this.ClassName %> GetByID(object id)
        {
            return (<%= this.ClassName %>)Awaken.Framework.Gateway.GetByID(EntityType, id);
        }

        public IList GetAll()
        {
            return Awaken.Framework.Gateway.GetAll(EntityType);
        }

        public void Save(IEntity entity)
        {
            Awaken.Framework.Gateway.Save(entity);
        }
        
        public void Delete(IEntity entity)
        {
            Awaken.Framework.Gateway.Delete(entity);
        }
        
        #endregion
    }
    #endregion
}
